import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";
import {OffsetDateTime} from "@js-joda/core";

export interface QueryMarketsGoodsRequest {
    name?: string
    barcode?: string
    categoryIds?: number[]
    brandIds?: number[]
    factoryIds?: number[]
}

export function queryMarketsGoods(id: number, pageable: Pageable, request: QueryMarketsGoodsRequest) {
    return fetcher.get<Page<QueryMarketsGoodsResponse>>(`/markets/${id}/goods`, {
        ...request,
        ...pageable.toRequestParams(),
    })
}


export interface QueryMarketsGoodsResponse {
    name: string
    amount: number
    price: number
    barcode: string
    createdDateTime: OffsetDateTime
    lastModifiedDateTime: OffsetDateTime
    id: number
    brand?: NumberIdAndName
    category?: NumberIdAndName
    factory?: NumberIdAndName
    boxSpecification?: string
    costPrice?: number
    amountInMarket: number
}

export function exportMarketsGoodsToExcel(id: number,request: QueryMarketsGoodsRequest) {
    return fetcher.get<Blob>(`/markets/${id}/goods/excel`, request,{
        responseType:3,
    })
}

export function getMarketGoodsBrands(marketId: number) {
    return fetcher.get<NumberIdAndName[]>(`/markets/${marketId}/goods/brands`)
}

export function getMarketGoodsCategories(marketId: number) {
    return fetcher.get<NumberIdAndName[]>(`/markets/${marketId}/goods/categories`)
}

export function getMarketGoodsFactories(marketId: number) {
    return fetcher.get<NumberIdAndName[]>(`/markets/${marketId}/goods/factories`)
}